import React from 'react'
import { domain } from '../../tools/config/var'
import { GetPPID } from '../../tools/fetch'

import './ProductItem.scss'

type Props = {
  data: Record<string, string>
  className?: string
}

export default class Notify extends React.PureComponent<Props, {}> {
  readonly state = {
    PPID: 0
  }

  public async componentDidMount () {
    const PPID = await GetPPID()
    if (typeof PPID === 'number') {
      this.setState({
        PPID: PPID
      })
    } else {
      // PPID获取出错了
    }
  }

  render () {
    const { className } = this.props
    const { id, imgurl, price, name: proName } = this.props.data
    return (
      <a
        className={`com_product_container ${className}`}
        // {:U('App1/Shop/goods',array('sid'=>0,'id'=>$v['id'],'ppid'=>$_SESSION['WAP']['vipid']))}
        href={`${domain}/Shop/goods/sid/0/id/${id}/ppid/${this.state.PPID}`}
      >
        <div className="img_container">
          <img src={`${domain}${imgurl}`} alt=""/>
        </div>
        <div className="text_container">
          <div className="name">{proName}</div>
        </div>
        <div className="text_container">
          <div className="price">￥{price}</div>
        </div>
      </a>
    )
  }
}
